package com.springboot.kaoqing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.kaoqing.entity.Kecheng;
import com.springboot.kaoqing.mapper.KechengMapper;
import com.springboot.kaoqing.qpage.QPage;
import com.springboot.kaoqing.service.IKechengService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.kaoqing.util.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-11-06
 */
@Service
public class KechengServiceImpl extends ServiceImpl<KechengMapper, Kecheng> implements IKechengService {

    /**
     * 分页查询分类
     * @param qPage
     * @return
     */
    @Override
    public IPage getPageList(QPage qPage, Kecheng obj) {
        QueryWrapper<Kecheng> queryWrapper=new QueryWrapper<>();
        if(obj.getKno()!=null&&!obj.getKno().equals("")){
            queryWrapper.like("kno",obj.getKno());
        }
        if(obj.getUid()!=null){
            queryWrapper.eq("uid",obj.getUid());
        }
        queryWrapper.orderByDesc("ctime");
        IPage<Kecheng> kechengIPage=this.page(new Page<>(qPage.getPage(), qPage.getRows()),queryWrapper);
        return kechengIPage;
    }

    /**
     * 新增
     * @param obj
     * @return
     */
    @Override
    public Result insert(Kecheng obj) {
        this.save(obj);
        return Result.reOk("恭喜，新增成功");
    }

    /**
     * 修改
     * @param obj
     * @return
     */
    @Override
    public Result updates(Kecheng obj) {
        Kecheng dto=this.getById(obj.getId());
        BeanUtils.copyProperties(obj,dto,new String[]{"id"});
        this.updateById(dto);
        return Result.reOk("恭喜，修改成功");
    }


}
